let DEV_BASE_URL = "";
let PRO_BASE_URL = "";

const EnvInfo = tt.getEnvInfoSync();

switch (EnvInfo.microapp.appId) {
  // 谷雨
  case "tt41fa3747decef57401":
    DEV_BASE_URL = "http://192.168.0.106:9792/csjmanage";
    PRO_BASE_URL = "https://video.weiyantj.cn/chunfen";
    break;
  // 觅得小剧场
  case "tt674411f9f875a12c01":
    DEV_BASE_URL = "http://192.168.0.106:9792/csjmanage";
    PRO_BASE_URL = "https://appmdl.mideyouapp.top/csjmidele";
    break;
  // 觅得剧场
  case "tt231655abbc260b9c01":
    DEV_BASE_URL = "http://192.168.0.106:9792/csjmanage";
    PRO_BASE_URL = "https://appmdl.mideyouapp.top/mdjc";
    break;
  // 春分
  case "tta1e4d7593ed0156801":
    DEV_BASE_URL = "http://192.168.0.106:9792/csjmanage";
    PRO_BASE_URL = "https://video.weiyantj.cn/chunfen";
    break;
  // 小满剧场
  case "ttb1f9c7442ecd057401":
    DEV_BASE_URL = "http://192.168.0.106:9790/csjmanage";
    PRO_BASE_URL = "https://video.weiyantj.cn/chunfen";
    break;
  // 暖冬剧场
  case "tt419d3720dea9f4e301":
    DEV_BASE_URL = "http://192.168.0.106:9790/csjmanage";
    PRO_BASE_URL = "https://video.weiyantj.cn/chunfen";
  // 青瓜剧场
  case "tt1c3a6a878330de6c01":
    DEV_BASE_URL = "http://192.168.0.106:9792/csjmanage";
    PRO_BASE_URL = "https://appmdl.mideyouapp.top/mdjc";
    break;
}

export const request = (options) => {
  options.method && (options.method = options.method.toUpperCase());
  return new Promise((resolve, reject) => {
    tt.request({
      url: EnvInfo.microapp.envType == "development" ? DEV_BASE_URL + options.url : PRO_BASE_URL + options.url,
      method: options.method || "GET",
      data: options?.data || {},
      header: options?.header || { "content-type": "application/json" },
      success: (res) => {
        try {
          resolve(res.data);
        } catch (err) {
          console.log(err);
        }
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
